
from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from selenium.webdriver.support.select import Select

class PersonalDataPage(BasePage):

    #当前界面的url
    url = "/crm/index.php?m=user&a=edit"

    #定位器
    #上传文件定位器
    file_upload_locator = (By.ID, "file_upload")
    #重命名用户名定位器
    username_re_locator = (By.CSS_SELECTOR,
                           "body > div.container > div.row > div:nth-child(2) > form > table > tbody > tr:nth-child(4) > td:nth-child(2) > input[type=text]")
    #重命名密码定位器
    password_re_locator = (By.ID, "password")
    #用户类型定位器
    user_category_locator = (By.ID, "category_id")
    #账户状态定位器
    account_status_locator = (By.ID, "status")
    #部门定位器
    department_locator = (By.ID, "department")
    #性别定位器
    sex_man_locator = (By.CSS_SELECTOR,
                       "body > div.container > div.row > div:nth-child(2) > form > table > tbody > tr:nth-child(10) > td:nth-child(2) > input[type=radio]:nth-child(1)")
    #email定位器
    email_locator = (By.CSS_SELECTOR,
                     "body > div.container > div.row > div:nth-child(2) > form > table > tbody > tr:nth-child(11) > td:nth-child(2) > input")
    #手机号定位器
    phone_locator = (By.CSS_SELECTOR,
                     "body > div.container > div.row > div:nth-child(2) > form > table > tbody > tr:nth-child(12) > td:nth-child(2) > input")
    #地址定位器
    address_locator = (By.NAME, "address")
    #保存定位器
    save_locator = (By.CSS_SELECTOR,
                    "body > div.container > div.row > div:nth-child(2) > form > table > tfoot > tr > td:nth-child(2) > input.btn.btn-primary")

    #保存成功定位器
    save_alert_locator = (By.CSS_SELECTOR,  'body > div.container > div.row > div:nth-child(1) > div')


    #执行的页面操作
    #上传文件
    def file_upload(self):
        self.find_element(self.file_upload_locator).send_keys(r"C:\Users\刘文良\Desktop\project_3\datas\123.png")
    #清除用户名
    def input_usernmae_re_clear(self):
        self.find_element(self.username_re_locator).clear()
    #输入用户名
    def input_username_re(self,username_re):
        self.find_element(self.username_re_locator).send_keys(username_re)
    #输入密码
    def input_password_re(self,password_re):
        self.find_element(self.password_re_locator).send_keys(password_re)
    #选择用户类型选择框
    def choice_user_category_select(self,text1):
        user_element = self.find_element(self.user_category_locator)
        user_select = Select(user_element)
        user_select.select_by_visible_text(text1)
    #选择用户状态选择框
    def choice_account_status_select(self, text2):
        account_status_element = self.find_element(self.account_status_locator)
        account_status_select = Select(account_status_element)
        account_status_select .select_by_visible_text(text2)
    #选择部门选择框
    def choice_department_select(self, text3):
        department_element = self.find_element(self.department_locator)
        department_select = Select(department_element)
        department_select.select_by_visible_text(text3)
    #选择性别
    def choice_sex_click(self):
        self.find_element(self.sex_man_locator).click()
    #清除邮箱
    def email_clear(self):
        self.find_element(self.email_locator).clear()
    #输入邮箱
    def email_input(self,email):
        self.find_element(self.email_locator).send_keys(email)
    #清除手机号
    def phone_clear(self):
        self.find_element(self.phone_locator).clear()
    #输入手机号
    def phone_input(self,phone):
        self.find_element(self.phone_locator).send_keys(phone)
    #清除地址
    def address_clear(self):
        self.find_element(self.address_locator).clear()
    #输入地址
    def address_input(self,address):
        self.find_element(self.address_locator).send_keys(address)
    #点击保存
    def save_click(self):
        self.find_element(self.save_locator).click()
    #得到弹窗文本信息
    def get_alert_text(self):
        return self.find_element(self.save_alert_locator).text


